

// key recogniser function is used to verify the key sent form the client.

key_recogniser = function(p_client){
	
	m_z = 36969 * (m_z & 65535) + (m_z >> 16);
	m_w = 18000 * (m_w & 65535) + (m_w >> 16);
	
	keyServer = (m_z << 16) + m_w; 
	
	trace("---key generated at server is--- :", keyServer);
	
	keyHandlerObj = new keyHandler();
	keyHandlerObj.client = p_client;
	
	p_client.call("send_key", keyHandlerObj);  //call client function to request unique keys 
												  //to be verified to continue streaming
		
}

keyHandler = function(){
		
		this.onResult = function(res){
		
			trace("Key received from client is: " + res);
			keyClient = res;
			
			if(keyClient == keyServer)
			{	
				trace("---!!!! key verified !!!!---");			
			}
			else
			{   
				trace("---key not verified---",keyClient);
				trace("Unauthorised connection not accepted...");
				application.disconnect(this.client);
				
			}
		}
		this.onStatus = function(info){
		
			trace("Failed with code:" + info.code);
			trace("Unauthorised connection not accepted...");
			application.disconnect(this.client);
		}
	};